{{ define "/admin/purview/add" }}

{{ template "public/header" }}

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:left" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="pid" class="layui-form-label">
                    <span class="x-red">*</span>父级名称
                </label>
                <div class="layui-input-inline">
                    <select id="pid" name="pid" lay-search>
                        <option value="0">顶级菜单</option>
                        {{ .treeHtml }}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="purviewName" class="layui-form-label">
                    <span class="x-red">*</span>权限名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="purviewName" name="name" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="controller" class="layui-form-label">
                    url
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="controller" name="url" placeholder="例如：/admin/index/index"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="is_show" class="layui-form-label">
                    <span class="x-red">*</span>是否显示
                </label>
                <div class="layui-input-inline">
                    <select id="is_show" name="is_show" required  lay-verify="required">
                        <option value="">未选择</option>
                        <option value="1">显示</option>
                        <option value="2">不显示</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="sort" class="layui-form-label">
                    <span class="x-red">*</span>排序
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="sort" name="sort" required  lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="sort" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">
                    提交
                </button>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form
        var layer = layui.layer
        //监听提交
        form.on('submit(add)', function (obj) {
            $.ajax({
                type: "post",
                url: obj.form.action,
                data: obj.field,
                dataType: "json",
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 2000//2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</html>
{{ end }}